package com.twu.biblioteca;


import java.util.ArrayList;

public class User {
    private static int nextLibraryNumber = 1111111;

    private String name;
    private String emailId;
    private String phoneNo;
    private int libraryNumber;
    private String password;
    private String username;

    public User(String name, String emailId, String phoneNo,String password) {
        this.name = name;
        this.emailId = emailId;
        this.phoneNo = phoneNo;
        this.password = password;
        this.libraryNumber = nextLibraryNumber++;
        this.username=(libraryNumber / 10000) + "-" + (libraryNumber % 10000);

    }

    public String getLibraryNumber() {
        return (libraryNumber / 10000) + "-" + (libraryNumber % 10000);
    }


    public String getUsername() {
        return username;
    }
    /*
    public static User authenticate(String username,String password){
        for (User user : users){
            if (user.getUsername().equals(username) && (user.password).equals(password)){
                return user;
            }
        }
        return null;
    }    */

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (libraryNumber != user.libraryNumber) return false;
        if (emailId != null ? !emailId.equals(user.emailId) : user.emailId != null) return false;
        if (name != null ? !name.equals(user.name) : user.name != null) return false;
        if (password != null ? !password.equals(user.password) : user.password != null) return false;
        if (phoneNo != null ? !phoneNo.equals(user.phoneNo) : user.phoneNo != null) return false;
        if (username != null ? !username.equals(user.username) : user.username != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (emailId != null ? emailId.hashCode() : 0);
        result = 31 * result + (phoneNo != null ? phoneNo.hashCode() : 0);
        result = 31 * result + libraryNumber;
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (username != null ? username.hashCode() : 0);
        return result;
    }


    public String getName() {
        return name;
    }

    public String getPhoneNo() {
        return phoneNo;
    }

    public String getEmailId() {
        return emailId;
    }

    public String getPassword() {
        return password;
    }

    public static void cleanUp() {
            nextLibraryNumber = 1111111;

    }
}
